home *** CD-ROM | disk | FTP | other *** search
- #ifndef FWNEWHEL_H
- #define FWNEWHEL_H
- //========================================================================================
- //
- // File: FWNewHel.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWAUTODE_H
- #include "FWAutoDe.h"
- #endif
-
- #ifndef FWEXCTAS_H
- #include "FWExcTas.h"
- #endif
-
- #ifndef FWEXCDEF_H
- #include "FWExcDef.h"
- #endif
-
- #ifdef FW_USE_NEW_HELPER
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // CLASS FW_CPrivSubHelper
- //========================================================================================
-
- class FW_CPrivSubHelper
- {
- public:
-
- static void InitializeStorageArray(FW_SPrivExceptionGlobals& globals,
- FW_CPrivSubHelper*array, int size);
-
- private:
-
- friend class FW_CLASS_ATTR FW_CPrivNewHelper;
- // FW_CPrivSubHelper should be a nested class of FW_CPrivNewHelper
-
- void* operator new(size_t size);
- void operator delete(void* object);
-
- FW_CPrivSubHelper(_FW_CAutoDestructObject *subObject,
- size_t subObjectSize,
- FW_CPrivSubHelper *nextSubHelper);
- ~FW_CPrivSubHelper();
-
- _FW_CAutoDestructObject *fSubObject;
- // The subobject being constructed.
-
- size_t fSubObjectSize;
- // The size of the subobject being watched.
- // This information is necessary for tracking nested subobjects.
-
- void *fSubObjectVTable;
- // The objects vtable at time of last completed constructor
-
- FW_CPrivSubHelper *fSiblings;
- // Next link for subobject peer to this one.
- };
-
- //========================================================================================
- // CLASS FW_CPrivNewHelper
- //
- // This helper object watches a dynamically allocated object until it is fully
- // constructed. If an exception is thrown before the object is fully constructed,
- // this helper will delete the object.
- //========================================================================================
-
- class FW_CPrivNewHelper FW_AUTO_DESTRUCT_OBJECT
- {
-
- public:
-
- friend class FW_CLASS_ATTR _FW_CAutoDestructObject;
-
- enum
- {
- kMaxNewHelperStackItems = 100,
- // Maximum items on NewHelper stack.
- // This limits 'nested news', i.e. objects that are newed that have
- // constructors that new objects that have constructors that new objects...
- kNewHelperStackSize = kMaxNewHelperStackItems*sizeof(FW_CPrivNewHelper*),
- // New helper stack size in bytes.
-
- kSubHelperArraySize = 100,
- // Maximum number of simultaneously tracked subobjects.
- // Subobjects are only tracked until their parent object's constructor
- // has fully executed.
- kSubHelperArrayByteSize = kSubHelperArraySize*sizeof(FW_CPrivSubHelper)
- // Subobject helper array size in bytes.
- };
-
- FW_CPrivNewHelper(__FW_OperatorNewHandler newHandler,
- __FW_OperatorDeleteHandler deleteHandler);
- ~ FW_CPrivNewHelper();
-
- _FW_CAutoDestructObject *WatchObject(_FW_CAutoDestructObject *watchedObject,
- size_t watchedSize) const;
- // Watch watchedObject, return previous watched object.
- // This method is not really const,
- // but it reduces unnecessary warnings to declare it so.
-
- _FW_CAutoDestructObject *ForgetObject() const;
- // Stop watching any object.
- // This method is not really const,
- // but it reduces unnecessary warnings to declare it so.
-
- void DeleteWatchedObject();
- // Delete the watched object, including subojects of partially constructed class.
-
- void UpdateForEndConstructor(_FW_CAutoDestructObject *object, size_t size);
- // This method is called only from the FW_END_CONSTRUCTOR macro.
-
- void PushNewHelper();
- // Push this helper onto the helper stack.
-
- short IsWatching(_FW_CAutoDestructObject *object) const;
- // Return 1 if this new helper is tracking object
-
- static short IsSubObject(void* subObject, void* object, size_t objectSize);
-
- static void Initialize(FW_SPrivExceptionGlobals& globals);
- // Initialize the NewHelper and SubHelper modules
-
- static void Terminate();
- // Terminate (cleanup) the NewHelper and SubHelper modules
-
- static FW_CPrivNewHelper *PopNewHelper();
- // Pop top item from helper stack and return pointer to it.
-
- static FW_CPrivNewHelper *TopNewHelper();
- // Return pointer to top item on helper stack, but don't pop.
-
- private:
-
- FW_CPrivSubHelper* InList(_FW_CAutoDestructObject *subObject);
- // Search list for entry tracking subObject.
- // Returns NULL if no entry exists.
-
- _FW_CAutoDestructObject *fWatchedObject;
- // The object being constructed.
-
- void *fObjectVTable;
- // The objects v table at time of last completed constructor
-
- size_t fWatchedSize;
- // The size of the object being watched.
- // This information is necessary for tracking subobjects.
-
- FW_CPrivSubHelper *fSubHelperList;
- // First link for SubHelper tracking subojects nested in this object.
- // Each subhelper tracks one subobject of the fWatchedObject.
-
- __FW_OperatorNewHandler fNewHandler;
- // The new handler to use to create memory block.
-
- __FW_OperatorDeleteHandler fDeleteHandler;
- // The delete handler to use to delete the memory block if necessary.
- };
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivNewHelper::IsSubObject
- //----------------------------------------------------------------------------------------
-
- inline short FW_CPrivNewHelper::IsSubObject(void* subObject, void* object, size_t objectSize)
- {
- return (subObject>object && (char*)subObject < (char*)object+objectSize);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivNewHelper::IsWatching
- //----------------------------------------------------------------------------------------
-
- inline short FW_CPrivNewHelper::IsWatching(_FW_CAutoDestructObject *object) const
- {
- return (object>=fWatchedObject && (char*)object < (char*)fWatchedObject+fWatchedSize);
- }
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
-
- #endif // FW_USE_NEW_HELPER
-
- #endif
-